<template>
    <div class="profitTableDetail">
        <el-breadcrumb separator="/" class="bread-title">
            <el-breadcrumb-item :to="{ path: '/profitTable'}">利润激励</el-breadcrumb-item>
            <el-breadcrumb-item>员工分配表</el-breadcrumb-item>
        </el-breadcrumb>

        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="员工姓名：">
                <el-input placeholder="请输入名称" v-model.trim="ruleForm.staffName" maxlength="20"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary"  @click="searchList" id="monitorEnter">查询</el-button>
                <el-button type="primary"  @click="exportreport">导出</el-button>
                <el-button type="primary"  @click="adjustreport">调整报表</el-button>
            </el-form-item>
        </el-form>

        <h3>{{ruleForm.yearTime}}年好生活员工分配表</h3>
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column label="序号" width="50" :formatter="inittotal" align="center"></el-table-column>
            <el-table-column label="工号" prop="staffCode"  align="center">
                <template slot-scope="scope">
                  <p v-if="scope.$index !==0" > {{scope.row.staffCode}}</p>
                  <p v-else>——</p>
                </template>  
            </el-table-column>
            <el-table-column label="姓名" prop="staffName"  align="center">
                <template slot-scope="scope">
                  <p v-if="scope.$index !==0" > {{scope.row.staffName}}</p>
                  <p v-else>——</p>
                </template> 
            </el-table-column>
            <el-table-column label="部门"  prop="departmentName" align="center">
                <template slot-scope="scope">
                  <p v-if="scope.$index !==0" > {{scope.row.departmentName}}</p>
                  <p v-else>——</p>
                </template> 
            </el-table-column>
            <el-table-column label="岗位名称"  prop="stationName"  align="center">
                <template slot-scope="scope">
                  <p v-if="scope.$index !==0" > {{scope.row.stationName}}</p>
                  <p v-else>——</p>
                </template> 
            </el-table-column>
            <el-table-column label="入职时间"  prop="onOrganizationStart"  align="center">
                <template slot-scope="scope">
                  <p v-if="scope.$index !==0" > {{scope.row.onOrganizationStart}}</p>
                  <p v-else>——</p>
                </template> 
            </el-table-column>
            <el-table-column label="离职时间"  prop="onOrganizationEnd"  align="center">
                <template slot-scope="scope">
                  <p v-if="scope.$index !==0" > {{scope.row.onOrganizationEnd}}</p>
                  <p v-else>——</p>
                </template> 
            </el-table-column>
            <el-table-column label="在岗天数"  prop="onOrganizationDays"   align="center">
                <template slot-scope="scope">
                   <p v-if="scope.$index !==0" > {{scope.row.onOrganizationDays}}</p>
                   <p v-else>——</p>
                </template> 
            </el-table-column>
            <el-table-column label="实际金额(元)"  prop="actuallyAmount" :formatter="initCash" align="center"></el-table-column>
             <el-table-column label="调整金额(元)"  prop="adjustedAmount" :formatter="initCash"  align="center"></el-table-column>
             <el-table-column label="实发金额(元)"  prop="actGrantAmount" :formatter="initCash"  align="center"></el-table-column>
        </el-table>

        <div class="pagebar">
          <el-pagination
            background
            layout="total, sizes, prev, pager, next"
            :current-page.sync="ruleForm.pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="ruleForm.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="totalSize">
          </el-pagination>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import api from '@/api/apiPath'
    export default {
        name: 'profitTableDetail',
        data() {
            return {
                tableData: [],
                ruleForm:{
                    staffName:undefined,
                    pageNum: 0,
                    pageSize: 10,
                    yearTime:undefined,
                },
                totalSize:0,
                reportId:undefined,//报表id
            }
        },
        created() {
            this.reportId = this.$route.query.reportId
            this.ruleForm.yearTime = this.$route.query.yearTime
            this.getlist()
        },
        mounted() {
            
        },
        methods: {
            handleCurrentChange(){
                this.getlist()
            },
            handleSizeChange(val){
                this.ruleForm.pageSize = val
                this.getlist();
            },
            inittotal(row, column, cellValue, index){
                if(index == 0){
                    return '合计';
                }
                return index
            },
            initCash(row, column, cellValue, index){
                 if(!cellValue && typeof cellValue!="undefined" && cellValue!=0){
                     return  '——'
                 } 
                if (index == 0) { 
                    if (typeof (cellValue) =="undefined" ){
                        return '——'
                    }
                }
                if(cellValue !== 0){
                    return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
                }
                if(cellValue == 0){
                    return "0.00"
                }
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist()
            },
            //报表导出。 
            exportreport(){
                this.axios.post(api.PROFITREPORT,{timeTag: this.ruleForm.yearTime}).then((res) => {
                    if (res.data.code == 200) {
                       this.$alert('已导出，请前往报表查询下载', {
                           confirmButtonText: '确定',
                         });
                    }
                })
            },
            adjustreport(){
                this.$router.push({path:'/profittableReportAdjust',query:{yearTime:this.ruleForm.yearTime,reportId:this.reportId}})
            },
            getlist(){
                this.axios.post(api.AWARDSALLOTINFO,this.ruleForm).then((res) => {
                    if (res.data.code == 200) {
                        this.tableData = res.data.data.list;
                        this.totalSize = res.data.data.total;
                    }
                })
            }


        },
        components: {},
        computed: {}
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus">

</style>
